<?php
header("Content-Type: text/html; charset=utf-8");
require_once '../smarty/Smarty.class.php';
require_once '../lib/pagination.php';
require_once '../lib/query_railway.php';
require_once '../lib/base.php';
$user=$_SESSION["RU"];
//var_dump($user);
if(!$user)header("Location:../user/login.php");
if($user["nick"]!="admin")exit;
if($_POST["act"]=="add") {
	$box=urldecode($_POST["b"]);
	$data[0]="type";
	$data[1]="'$box'";
	$op= QR::add_data($tb_box,$data);
	if($op>=0)echo "100" ;else echo "添加失败，请检查输入的正确性！";
	exit;
}
if($_POST["act"]=="del") {
	$box=urldecode($_POST["b"]);
	$str="type='".$box."'";
	$op= QR::del_data($tb_box,$str);
	if($op>0)echo "100" ;else echo "删除失败！或许数据已经被删除！";
	exit;
}
$p=($_GET["p"]==null)|($_GET["p"]==0) ?1:$_GET["p"];
$PAGE_NUM=15;
$from=($p-1)*$PAGE_NUM;

//$sz=htmlspecialchars( $_GET["sz"]);
$b=htmlspecialchars($_GET["b"]);
//$zc=htmlspecialchars($_GET["zc"]);
//$ze=htmlspecialchars($_GET["ze"]);
$str=" type<>''";
if ($b){
	if($b)$str.=" and type like '%$b%'";
	//if($zz)$str.=" and border like '%$zz%'";
	//if($zc)$str.=" and $tb_end.code like '%$zc%'";
	//if($ze)$str.=" and $tb_end.en like '%$ze%'";
}
$dbtable ="$tb_box";
$count=QR::get_total($dbtable, $str);//all_number
//echo "<br/>".$count."<br/>";
$field="*";
$str.=" order by type";
$data=QR::get_data($dbtable, $field,$str,$from,$PAGE_NUM);//all_data
//var_dump($data);

//$start=QR::get_field($tb_start,"en");
$box=QR::get_field($tb_box,"type");
//$end=QR::get_field($tb_end,"en");
$smarty = new Smarty;
$smarty->assign("leftpanel",leftpanel("RW",4));
$smarty->assign("userdata",$data);
$smarty->assign("pagination", getPageNavigation($p,$count,$PAGE_NUM));
//$smarty->assign("start",json_encode($start));
$smarty->assign("box",$box);
//$smarty->assign("end",json_encode($end));
//$smarty->assign("sz",$sz);
$smarty->assign("b",$b);
//$smarty->assign("zc",$zc);
//$smarty->assign("ze",$ze);
$smarty->assign("user",$user);
$smarty->display('railway_list_box.tpl');
?>